package br.com.oversea.hibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
// class used for get database connections
	
	private static final SessionFactory session =  new AnnotationConfiguration().configure().buildSessionFactory();
	// object session factory 
	
	
	private static SessionFactory buildSessionFactory() {

		try {
	
			// pass the  configuration file of the hibernate
			Configuration cfg = new Configuration();
			cfg.configure("hibernate.cfg.xml");
			return cfg.buildSessionFactory();
			
			
		} catch (Throwable e) {
	
			// show for the user the error if existsq
			System.out.println(" Erro de conexao com o banco de dados  \n" + e);
			throw new ExceptionInInitializerError();
		}
	}
	
	// method used for get the connections
	public static SessionFactory getSession() {
		return session;
	}
	
	
}
